home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch01 / realtek.asm < prev    next >
Assembly Source File  |  1993-09-01  |  12KB  |  393 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file realtek.ASM
  3. ;
  4. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. ; Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6. ; Copyright (C) 1993 R Mattolini, 113 v. Guerrazzi, Sesto F.no Italy 50019
  7. ;
  8. ; This file is distributed under the terms listed in the document
  9. ; "copying.dj", available from DJ Delorie at the address above.
  10. ; A copy of "copying.dj" should accompany this file; if not, a copy
  11. ; should be available from where this file was obtained.  This file
  12. ; may not be distributed without a verbatim copy of "copying.dj".
  13. ;
  14. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  15. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. ;--------------------------------------------------------------------------
  17.  
  18. include grdriver.inc
  19. cseg    segment byte public 'code'
  20.     assume  cs:cseg, ds:cseg, es:cseg, ss:nothing
  21.  
  22. req_T28         equ    0        ; enable  80x28x16 text mode
  23. req_T50         equ    0        ; enable  80x50x16 text mode
  24. req_3516        equ    0        ; enable  720x350x16 graphics mode
  25. req_4816        equ    0        ; enable  720x480x16 graphics mode
  26. req_lowX        equ    0        ; enable  320x240/320x400/360x480 256 color modes
  27. req_hiX         equ    0        ; enable  high resolution mode X support
  28.  
  29. ;--------------------------------------------------------------------------
  30. ; DRIVER HEADER
  31. ;  The following entries MUST match the structure and constant
  32. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  33. ;  The mode word should contain the following bitfields:
  34. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  35. ;     - the adapter type field should be specified
  36. ;     - the memory size field should be specified
  37. ;     - the paging mode field should be specified
  38. ;  The mode set routine will OR in the plane bitfield as it will
  39. ;  change when different color number modes are requested.
  40. ;--------------------------------------------------------------------------
  41.  
  42.     dw    offset mode_set_routine
  43.     dw    offset paging_routine
  44. mode_W  dw    GRD_NEW_DRIVER+GRD_VGA+GRD_1024K+GRD_RW_64K
  45. ;
  46. ; The 'def_xx' fields are filled in by go32 from the corresponding
  47. ; fields of the 'GO32' environment variable
  48. ;
  49. def_tw  dw    80        ; text width
  50. def_th  dw    25        ; text height
  51. def_gw  dw    640        ; graphics width
  52. def_gh  dw    480        ; graphics height
  53. def_nc  dw    16        ; graphics colors
  54.     dw    offset driver_init_routine
  55.     dw    offset text_mode_table
  56.     dw    offset graphics_mode_table
  57.  
  58. ;
  59. ; Biggest text and graphics sizes
  60. ;
  61. Max_TW  equ    132
  62. Max_TH  equ    60
  63. Max_GWn equ    800        ; non interlaced!!!
  64. Max_GHn equ    600
  65. Max_GW  equ    1024        ; may be interlaced
  66. Max_GH  equ    768
  67.  
  68.  
  69. ;--------------------------------------------------------------------------
  70. ; TABLE OF SUPPORTED TEXT MODES
  71. ;    - keep sorted by size
  72. ;    - end with an all 0 entry
  73. ;    - BIOS field = 0xff disables it
  74. ;    - fields:
  75. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  76. ;--------------------------------------------------------------------------
  77. text_mode_table        label word
  78.     dw    80,    25,    2,    007h +  00000h
  79.     dw    40,    25,    16,    001h +  00000h
  80.     dw    80,    25,    16,    003h +  00000h
  81.     if req_T28
  82.     dw      80,     28,     16,     003h +  val_T28
  83.     endif
  84.     dw    80,    30,    16,    018h +  00000h
  85.     dw    80,    43,    16,    019h +  00000h
  86.     if req_T50
  87.     dw      80,     50,     16,     003h +  val_T50
  88.     endif
  89.     dw    80,    60,    16,    01ah +  00000h
  90.     dw    132,    25,    16,    01bh +  00000h
  91.     dw    132,    30,    16,    01ch +  00000h
  92.     dw    132,    43,    16,    01dh +  00000h
  93.     dw    132,    60,    16,    01eh +  00000h
  94.     dw    0,    0,    0,    000h +  00000h
  95.  
  96.  
  97. ;--------------------------------------------------------------------------
  98. ; TABLE OF SUPPORTED GRAPHICS MODES
  99. ;    - keep sorted first by colors then by size
  100. ;    - end with an all 0 entry
  101. ;    - BIOS field = 0xff disables it
  102. ;    - fields:
  103. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  104. ;--------------------------------------------------------------------------
  105. graphics_mode_table    label word
  106.     dw    320,    200,    16,    00dh +  00000h
  107.     dw    640,    200,    16,    00eh +  00000h
  108.     dw    640,    350,    16,    010h +  00000h
  109.     dw    640,    480,    16,    012h +  00000h
  110.     if req_3516
  111.     dw      720,    350,    16,     val_3516        ; Tweaked 16 color mode
  112.     endif
  113.     if req_4816
  114.     dw      720,    480,    16,     val_4816        ; Tweaked 16 color mode
  115.     endif
  116.     dw    800,    600,    16,    01fh +  00000h
  117.     dw    960,    720,    16,    020h +  00000h
  118.     dw    1024,    768,    16,    021h +  00000h
  119.     dw    1280,    1024,    16,    02ah +  00000h
  120.     dw    320,    200,    256,    013h +  00000h
  121. ;    dw      320,    200,    256,    013h +  val_hiX ; Mode X like
  122.     if req_lowX
  123.     dw      320,    240,    256,    val_lowXa       ; Mode X      (<64k)
  124.     dw      320,    400,    256,    val_lowXb       ; Mode X      (<64k)
  125.     dw      360,    480,    256,    val_lowXc       ; Mode X      (<64k)
  126.     endif
  127.     dw    640,    400,    256,    025h +  00000h
  128.     dw    512,    512,    256,    024h +  00000h
  129.     dw    640,    480,    256,    026h +  00000h
  130.     dw    800,    600,    256,    027h +  00000h
  131.     dw    1024,    768,    256,    028h +  00000h
  132.     dw    1024,    1024,    256,    029h +  00000h
  133.     dw    0,    0,    0,    000h +  00000h
  134.  
  135.  
  136. ;--------------------------------------------------------------------------
  137. ; TABLE OF SPECIAL SETUP PROCEDURES
  138. ;  You may need such procedures for:
  139. ;     -- reloading fonts on standard EGA or VGA for
  140. ;     higher resolution text modes
  141. ;     -- enable HiColor mode of some Super VGAs
  142. ;     -- Handle the parameter passing conventions of the VESA BIOS
  143. ;     -- put VGA into 256 color plane mode ("MODE X")
  144. ;     -- etc...
  145. ;  There should be one entry in the table for every non-zero
  146. ;  'setup_procedure_index' in the text and graphics mode tables.
  147. ;  The first entry in the table belongs to index 100h, and so on.
  148. ;  The special setup procedure is invoked via a near call.
  149. ;
  150. ;  Entry: DI=address of the mode record from the text or graphics
  151. ;      table to set up.
  152. ;
  153. ;  Exit:  Adapter configured
  154. ;      BX=driver mode word as it should be returned by the mode set
  155. ;         routine. Typically it involves picking up the mode word
  156. ;         from the header and OR-ing in the appropriate bitplane mode
  157. ;         bitfield. (This is not needed for text modes)
  158. ;      AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  159. ;
  160. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  161. ;--------------------------------------------------------------------------
  162. special_setup_table    label word
  163. ;       No chipset specific set up routines other than in vgaext.inc needed
  164.  
  165. ;include vgaext.inc      ; load VGA non BIOS modes
  166.  
  167.  
  168. ;--------------------------------------------------------------------------
  169. ; DRIVER INIT ROUTINE
  170. ;  called once after the driver is loaded
  171. ;  may do one or more of the followings:
  172. ;    - check for proper board type
  173. ;    - check amount of RAM on board, and:
  174. ;    -- update word in header to reflect correct amount
  175. ;    -- disable modes in the tables for which there is not enough RAM
  176. ;    - check for special equipment (HiColor DAC, etc...)
  177. ;
  178. ;  Entry: nothing
  179. ;
  180. ;  Exit:  AX=status:
  181. ;       non-zero: OK,
  182. ;       0: something went wrong (e.g. wrong adapter, etc..)
  183. ;      BX,CX,DX may be trashed
  184. ;
  185. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  186. ;--------------------------------------------------------------------------
  187. driver_init_routine    proc    far
  188.     mov    ax,1
  189.     ret
  190. driver_init_routine    endp
  191.  
  192.  
  193. ;--------------------------------------------------------------------------
  194. ; MODE SET ROUTINE
  195. ;  sets up a text or graphics mode as close as possible to the one
  196. ;  reguested by the user with regard to number of colors and size.
  197. ;
  198. ;  Entry: AX=mode selection
  199. ;     0 = 80x25 text
  200. ;     1 = default text
  201. ;     2 = text CX cols by DX rows
  202. ;     3 = biggest text
  203. ;     4 = 320x200 graphics
  204. ;     5 = default graphics
  205. ;     6 = graphics CX width by DX height
  206. ;     7 = biggest non-interlaced graphics
  207. ;     8 = biggest graphics
  208. ;     9 = graphics BX colors, CX width by DX height
  209. ;
  210. ;  Exit: BX=driver mode flag
  211. ;     CX=width (in pixels or characters)
  212. ;     DX=height
  213. ;
  214. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  215. ;     YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  216. ;     MUCH TABLE DRIVEN
  217. ;--------------------------------------------------------------------------
  218. mode_set_routine    proc    far
  219.     push    ds
  220.     push    di
  221.     push    si
  222.     mov    si,cs
  223.     mov    ds,si
  224.     cmp    ax,9
  225.     jbe    DoIt
  226.     jmp    Exit
  227. DoIt:    add    ax,ax
  228.     mov    si,ax
  229.     jmp    WORD PTR mode_set_table[si]
  230. mode_set_table  label    word
  231.     dw    offset mode_0
  232.     dw    offset mode_1
  233.     dw    offset mode_2
  234.     dw    offset mode_3
  235.     dw    offset mode_4
  236.     dw    offset mode_5
  237.     dw    offset mode_6
  238.     dw    offset mode_7
  239.     dw    offset mode_8
  240.     dw    offset mode_9
  241. mode_0: mov    si,offset text_mode_table    ; 80x25 text
  242.     mov    bx,def_nc
  243.     mov    cx,80
  244.     mov    dx,25
  245.     jmp    Lookup
  246. mode_1: mov    si,offset text_mode_table    ; default text
  247.     mov    bx,def_nc
  248.     mov    cx,def_tw
  249.     mov    dx,def_th
  250.     jmp    Lookup
  251. mode_2: mov    si,offset text_mode_table    ; CX*DX text
  252.     mov    bx,def_nc
  253.     jmp    Lookup
  254. mode_3: mov    si,offset text_mode_table    ; biggest text
  255.     mov    bx,def_nc
  256.     mov    cx,Max_TW
  257.     mov    dx,Max_TH
  258.     jmp    Lookup
  259. mode_4: mov    si,offset graphics_mode_table    ; 320x200 graphics
  260.     mov    bx,def_nc
  261.     mov    cx,320
  262.     mov    dx,200
  263.     jmp    Lookup
  264. mode_5: mov    si,offset graphics_mode_table    ; default graphics
  265.     mov    bx,def_nc
  266.     mov    cx,def_gw
  267.     mov    dx,def_gh
  268.     jmp    Lookup
  269. mode_6: mov    si,offset graphics_mode_table    ; CX*DX graphics
  270.     mov    bx,def_nc
  271.     jmp    Lookup
  272. mode_7: mov    si,offset graphics_mode_table    ; biggest non-interlaced gr
  273.     mov    bx,def_nc
  274.     mov    cx,Max_GWn
  275.     mov    dx,Max_GHn
  276.     jmp    Lookup
  277. mode_8: mov    si,offset graphics_mode_table    ; biggest graphics
  278.     mov    bx,def_nc
  279.     mov    cx,Max_GW
  280.     mov    dx,Max_GH
  281.     jmp    Lookup
  282. mode_9: mov    si,offset graphics_mode_table    ; CX*DX graphics w/ BX colors
  283. ;
  284. ; At this point:
  285. ;   SI points to the table to search (text or graphics)
  286. ;   BX has colors
  287. ;   CX has width
  288. ;   DX has height
  289. ;
  290. Lookup: xor    ax,ax                ; last color number seen
  291. Find_C: cmp    [si+4],ax            ; last color number == this?
  292.     je    Same_C
  293.     jb    Prev_C                ; end of table -- use last color
  294.     cmp    BYTE PTR [si+6],0ffh        ; valid entry ?
  295.     je    Prev_C                ; not -- use last color
  296.     mov    ax,[si+4]            ; record color number
  297.     mov    di,si                ; start of entries w/ this color
  298.     cmp    ax,bx                ; enough colors ?
  299.     jae    Find_S
  300. Same_C: add    si,8
  301.     jmp    Find_C
  302. Prev_C: or    ax,ax                ; found any color at all?
  303.     je    Exit
  304. ;
  305. ; At this point:
  306. ;   DI points into the table to the first entry with the desired color
  307. ;      number (either it has enough colors or it is the highest color
  308. ;      number supported by the driver). Additionally, at least the
  309. ;      first (= smallest size) entry for this color is valid (has a
  310. ;      valid BIOS number).
  311. ;   AX has the color number adjusted for the driver
  312. ;   CX has width
  313. ;   DX has height
  314. ;
  315. Find_S: cmp    [di+4],ax            ; still the same color #?
  316.     jne    Prev_S
  317.     cmp    BYTE PTR [di+6],0ffh        ; valid entry ?
  318.     je    Prev_S
  319.     cmp    [di],cx
  320.     jb    Next_S
  321.     cmp    [di+2],dx
  322.     jae    GotIt
  323. Next_S: add    di,8
  324.     jmp    Find_S
  325. Prev_S: sub    di,8
  326. ;
  327. ; At this point:
  328. ;   DI points to the table entry we want to set up
  329. ;
  330. GotIt:  mov    ax,[di+6]            ; BIOS mode number
  331.     or    ah,ah                ; special ?
  332.     je    doBIOS
  333.     mov    al,ah
  334.     xor    ah,ah
  335.     dec    ax
  336.     add    ax,ax
  337.     mov    si,ax
  338.     call    WORD PTR special_setup_table[si]
  339.     jmp    RetVal
  340. doBIOS: int    10h
  341.     mov    bx,GRD_1_PLANE
  342.     cmp    WORD PTR [di+4],2        ; 2 colors ?
  343.     je    doFLAG
  344.     mov    bx,GRD_4_PLANES
  345.     cmp    WORD PTR [di+4],16        ; 16 colors ?
  346.     je    doFLAG
  347.     mov    bx,GRD_8_PLANES
  348.     cmp    WORD PTR [di+4],256        ; 256 colors ?
  349.     je    doFLAG
  350.     mov    bx,GRD_16_PLANES
  351.     cmp    WORD PTR [di+4],32768        ; 32K colors ?
  352.     je    doFLAG
  353.     mov    bx,GRD_PLANE_MASK        ; something is wrong!!
  354. doFLAG: or    bx,mode_W
  355. RetVal: mov    cx,[di]
  356.     mov    dx,[di+2]
  357. Exit:    pop    si
  358.     pop    di
  359.     pop    ds
  360.     ret
  361. mode_set_routine    endp
  362.  
  363.  
  364. ;--------------------------------------------------------------------------
  365. ; PAGING ROUTINE
  366. ;
  367. ;  Entry: AH=read page
  368. ;      AL=write page
  369. ;
  370. ;  Exit: VGA configured.
  371. ;     AX,BX,CX,DX,SI,DI may be trashed
  372. ;
  373. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  374. ;     This code must be relocatable and may not reference any data!
  375. ;--------------------------------------------------------------------------
  376.     assume  ds:nothing, es:nothing
  377.  
  378. paging_routine  proc    far
  379.     mov cx,ax
  380.     mov dx,3d6h
  381.     mov al,ch
  382.     out dx,al
  383.     inc dx
  384.     mov al,cl
  385.     out dx,al
  386.     ret
  387. paging_routine  endp
  388.  
  389. cseg    ends
  390.     end
  391.  
  392.  
  393.